package com.stropheware.droidDefense;

import android.content.Context;
import android.graphics.Canvas;
import android.util.Log;
import android.view.MotionEvent;

public class Menu {
	
	private static final String TAG = "MenuClass";
	
	private GameBoard gameBoard;
	
	private Context context;
	
	private BasicTower menuBasicTower;
	private AoETower menuAoETower;
	private UtilityTower menuUtilityTower;
	
	private int menuWidth;
	
	private int menuHeight;
	
	private int startSidePx;
	
	private float towerPartitionBottomPx;
	
	private float towerPadding;
	
	private float towerMidLeftPx;
	
	public boolean animatingTowerMove;
	
	public Menu(GameBoard gameBoard, Context context) {
		this.gameBoard = gameBoard;
		this.context = context;
		animatingTowerMove = false;
		menuWidth = gameBoard.actualMenuWidth;
		menuHeight = gameBoard.actualHeight;
		startSidePx = gameBoard.actualWidth - menuWidth;
		towerPartitionBottomPx = (menuHeight * 2) / 3;
		towerPadding = (towerPartitionBottomPx - (AbstractTower.TOWER_SIDE_LENGTH * gameBoard.cellSideLength * 3)) / 3;
		towerMidLeftPx = startSidePx + (menuWidth / 2) - 
			((AbstractTower.TOWER_SIDE_LENGTH * gameBoard.cellSideLength) / 2);
		menuBasicTower = new BasicTower(context, gameBoard, (int)towerPadding, (int)towerMidLeftPx);
		menuBasicTower.heading = 0;
		menuAoETower = new AoETower(context, gameBoard, (2 * (int)towerPadding) + (AbstractTower.TOWER_SIDE_LENGTH * 
				gameBoard.cellSideLength), (int)towerMidLeftPx);
		menuAoETower.heading = 0;
		menuUtilityTower = new UtilityTower(context, gameBoard, (3 * (int)towerPadding) +  
				2 *(AbstractTower.TOWER_SIDE_LENGTH * gameBoard.cellSideLength), (int)towerMidLeftPx);
		menuUtilityTower.heading = 0;
		if(MainActivity.DEBUG) {
			Log.d(TAG, "towerPadding:" + towerPadding);
			Log.d(TAG, "towerMidLeftPx:" + towerMidLeftPx);
			Log.d(TAG, "towerPartitionBottomPx:" + towerPartitionBottomPx);
		}
	}
	
	public void drawMenu(Canvas canvas) {
		menuBasicTower.drawDrawable(canvas);
		menuAoETower.drawDrawable(canvas);
		menuUtilityTower.drawDrawable(canvas);
		
	}
	
	public boolean touchFirstMenuTower(int x, int y) {
		return menuBasicTower.drawable.copyBounds().contains(x, y);
	}
	
	public boolean touchSecondMenuTower(int x, int y) {
		return menuAoETower.drawable.copyBounds().contains(x, y);
	}
	
	public boolean touchThirdMenuTower(int x, int y) {
		return menuUtilityTower.drawable.copyBounds().contains(x, y);
	}

}
